//添加多个参数注意使用[]
layui.use(['form', 'jquery'], function () {

    const form = layui.form,
        $ = layui.jquery;

    let id = sessionStorage.getItem("pmsMethodId");
    findById(id);

    /**
     * 查询单个
     * @param id
     */
    function findById(id) {

        let result = commonAjax(AUTH_SERVER_URL+'/permission/findById',{id:id},'get');
        setData(result.data);
    }

    /**
     * 赋值
     */
    function setData(data) {
        $('#id').val(data.id);
        $('#code').val(data.code);
        $('#name').val(data.name);
        $('#value').val(data.value);
        $('#uri').val(data.uri);

        form.render();
    }

    /**
     * 保存
     */
    form.on('submit(commit)', function (data) {

        let formData = JSON.stringify(data.field);
        let result = commonAjax(AUTH_SERVER_URL+'/permission/update',formData,'post');
        if (result.code === 200) {
            layerMsgSaveSuccess();
        } else {
            layerMsgSaveFail();
        }
        return false;
    });

});